package com.cskaoyan.gateway.controller.order;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.order.OrderDetailQueryService;
import com.mall.order.constant.OrderRetCode;
import com.mall.order.dto.OrderDetailRequest;
import com.mall.order.dto.OrderDetailResponse;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Connor
 * @date 2020/12/21
 * @Version 1.0
 */
@RestController
@RequestMapping("shopping")
public class QueryOrderDetailController {

    @Reference(timeout = 3000,check = false)
    private OrderDetailQueryService orderDetailQueryService;

    @GetMapping("order/{id}")
    public ResponseData queryOrderDetail(@PathVariable("id") String id) {
        OrderDetailRequest orderDetailRequest = new OrderDetailRequest(id);
        OrderDetailResponse orderDetailResponse = orderDetailQueryService.queryOrderDetail(orderDetailRequest);
        if (orderDetailResponse.getCode().equals(OrderRetCode.SUCCESS.getCode())) {
            return new ResponseUtil<>().setData(orderDetailResponse);
        }
        return new ResponseUtil<>().setErrorMsg(orderDetailResponse.getMsg());
    }
}
